package main
{
	import api.event.CallFunName;
	
	import base.GlobalData;
	
	import com.game.api.APICore;
	import com.game.btnClass.AddMouseEvent;
	import com.game.btnClass.BtnClass_goto;
	import com.game.display.DisManage;
	import com.game.utils.GlobalFun;
	
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	import flash.text.TextField;
	
	import mc.GameTestBtn;
	
	public class GameOver extends MovieClip
	{
		public var clewTxt:TextField;
		
		private var _btnListName:Array=["再来一次","推荐PVP"];
		private var _isUseLeave:Boolean=false;
		private var _btnEventList:Vector.<AddMouseEvent>=new Vector.<AddMouseEvent>();
		public function GameOver()
		{
			init();
		}
		private function init():void{
			GlobalData.apiCore.currClass=(this);
			copyBtnList();
			isDisRecommendBtn(4);
			APICore.getInstance().callAPIFun(CallFunName.A_SET_GAME_STATE,false);
		}
		private function gc():void{
			for(var i:uint=0;i<_btnEventList.length;i++){
				_btnEventList[i].delMouseEvent();
				_btnEventList[i]=null;
			}
			_btnEventList=null;
			isDisRecommendBtn();
			DisManage.delAllDis(this);
			DisManage.delAllDis();
			
		}
		private function copyBtnList():void{
			for(var i:uint=0;i<_btnListName.length;i++){
				var _btn:GameTestBtn=new  GameTestBtn();
				var _point:Point=GlobalFun.getListPoint(i,7,112,40);
				_btn.x=28+_point.x;
				_btn.y=42+_point.y;
				_btn.id=i;
				_btn.txt.text=_btnListName[i];
				this.addChild(_btn);
				_btnEventList.push(new BtnClass_goto(_btn,btnClick,null,null,true));
			}
		}
		private function btnClick(e:MouseEvent):void{
			var _btn:GameTestBtn=e.currentTarget as GameTestBtn;
			switch(_btn.id){
				case 0:
					sendAgain();
					break;
				case 1:
					recommend();
					break;
			}
		}
		//====================================
		//API调用游戏方法
		//初始化游戏公共方法
		public function  initPVP(data:*=null):void{
			gc();
			new InitAPI_PVP();
		}
		public function  stopGame(isStop:Boolean):void{
			
			if(isStop){
				
			}else{
				
			}
			
		}
		
		//====================================
		//调用API方法
		
		
		
		//====================================
		//游戏间通信方法
		private function isDisRecommendBtn(type:uint=0):void{
			GlobalData.apiCore.callAPIFun(CallFunName.A_IS_SHOW_RECOMMENDBTN,type);
		}
		private function recommend():void{
			GlobalData.apiCore.callAPIFun(CallFunName.A_SHOW_RECOMMEND);
		}
		private function sendAgain():void{
			if(GlobalData.isRobot){
				again();
			}else if(_isUseLeave){
				initPVP();
			}else{
				GlobalData.apiCore.callAPIFun(CallFunName.A_ASK_AGAIN);
			}
		}
		public function wantAgain(data:*=null):void{
			GlobalData.apiCore.callAPIFun(CallFunName.A_ACCEPT_AGAIN);
		}
		public function again(data:*=null):void{
			gc();
			
			DisManage.addDis(new Game());
		}
		public function UseChange(isAdd:Boolean=false):void{
			if(isAdd){
				clewTxt.text="用户加入!";
				initPVP();
			}else{
				clewTxt.text="用户已经退出!";
				_isUseLeave=true;
			}
		}
		
	}
}